<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增渠道信息')" />
    <th:block th:include="include :: select2-css" />


</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-channel-add">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">渠道编号：</label>
                <div class="col-sm-8">
                    <input name="channelCode" th:value="${channelCode}" readonly class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">渠道名称：</label>
                <div class="col-sm-4">
                    <input class="form-control" id="channelNameInput" onkeyup="channelNameInputFun();" type="text" required>
                    <span class="help-block m-b-none text-danger" style="display: none"  id="warning">该渠道号不可用，请重新输入</span>
                </div>
                <div class="col-sm-4">
                    <input name="channelName" id="channelName" class="form-control" readonly type="text" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">应用名称：</label>
                <div class="col-sm-8">
                    <select name="appType"  class="form-control">
                        <option  th:each="item:${appTypeList}" th:text="${item.name}" th:value="${item.value}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">渠道类型：</label>
                <div class="col-sm-8">
                    <select name="channelType"  class="form-control">
                        <option  th:each="item:${channelTypeList}" th:text="${item.name}" th:value="${item.value}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">渠道计价类型：</label>
                <div class="col-sm-8">
                    <select name="chargeType" id="chargeType"  class="form-control">
                        <option value="1">UV结算</option>
                        <option value="2">注册结算</option>
                        <option value="3">联登结算</option>
                    </select>
                </div>
            </div>

            <!--            只有注册计价的时候才需要设置该值-->
            <div class="form-group" id="channelRate" style="display: none">
                <label class="col-sm-3 control-label is-required">渠道比率：</label>
                <div class="col-sm-8">
                    <input name="channelRate" class="form-control" type="text" value="0" required>
                    <span style="color: red">渠道统计时，按照该值进行扣量（注册扣量）（例如：0.9。扣量10%）</span>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">渠道价格：</label>
                <div class="col-sm-8">
                    <input name="chargeAmount" class="form-control" type="text" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">落地页类型：</label>
                <div class="col-sm-8">
                    <select name="pageType" class="form-control">
                        <option  th:each="item:${typeList}" th:text="${item.name}" th:value="${item.type}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">不包括的产品：</label>
                <div class="col-sm-8">
                    <label class="check-box" th:each="item:${productList}">
                        <input type="checkbox" name="notIncludeProduct" th:value="${item.value}" th:text="${item.name}"></label>
                    </label>
                    <span style="color: red">该渠道不展示的产品信息</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">不包括的来源：</label>
                <div class="col-sm-8">
                    <label class="check-box" th:each="item:${sourceList}">
                        <input type="checkbox" name="notIncludeSource" th:value="${item.value}" th:text="${item.name}"></label>
                    </label>
                    <span style="color: red">该来源的请求不展示</span>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />

    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "extend/channel"
        $("#form-channel-add").validate({
            focusCleanup: true
        });

        function channelNameInputFun() {
            $('#channelName').val('')
            var channelNameInput = $('#channelNameInput').val();
            $.ajax({
                type: "post",
                url: prefix + "/checkName",
                data: {
                    "channelName": channelNameInput
                },
                success: function(res) {
                    if (res.code == 0) {
                        $('#warning').hide()
                        $('#channelName').val(res.data.channelName)
                        return;
                    }
                    $('#warning').show();
                }
            });
        }

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-channel-add').serialize());
            }
        }

        $('#chargeType').change(function () {
            var typeValue =$('#chargeType').val();
            if (typeValue == 2){
                $('#channelRate').show()
            }else{
                $('#channelRate').hide()
            }
        })

    </script>
</body>
</html>